package open.tech.dawn.core.base;

import cn.hutool.core.util.StrUtil;
import open.tech.dawn.core.error.ServiceException;

import java.lang.reflect.Field;

public class NullValueValidMethod extends EntityValidMethod {
    @Override
    public void valid(Object object, Field field, EntityValid entityValid) {
        String name = StrUtil.isBlank(entityValid.name()) ? field.getName() : entityValid.name();
        if (object == null)
            throw new ServiceException(name + "的值为空");
        if (object instanceof String) {
            if (StrUtil.isBlank(String.valueOf(object))) {
                throw new ServiceException(name + "的值为空");
            }
        }
    }
}
